﻿@{
    Layout = "~/Views/Shared/_TableLayout.cshtml";
    ViewBag.Title = "订单列表";
}
@section TopStyles{
    <style>
        .subnameright {
            text-align: right !important;
        }
    </style>

}

<label class="btn"> 订单状态：</label>
<select class="m-b field" name="orderstatus" id="orderstatus" title="订单状态" style="box-shadow: 0px 1px 1px rgba(90,90,90,0.1);
    padding: 5px 10px;
    font-size: 12px;
    line-height: 1.5;
    border-radius: 3px;padding-top: 3px;
    padding-bottom: 9px;" onchange="refreshTable()">
    <option value="0">全部</option>
    <option value="10">待付款</option>
    <option value="20">已发货</option>
    <option value="30">待收货</option>
    <option value="40">已收货</option>
</select>

<button id="btn_delete" type="button" class="btn btn-primary" onclick="doSyncPayResult()"><i class="fa fa-edit" aria-hidden="true"></i> 同步支付状态</button>

@section EditModal{
    <div class="modal inmodal" id="EditModal" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated fadeIn">
                <div class="modal-header">
                    <button id="dia_close" type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>

                </div>
                <div id="dia_body" class="modal-body">
                    <div class="ibox-content">
                        <form class="form-horizontal m-t" id="commentForm">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">商品名称：</label>
                                <div class="col-sm-8">
                                    <input id="Title" type="text" class="form-control field" name="Title">
                                </div>
                            </div>
                            @*<div class="form-group">
                                    <label class="col-sm-3 control-label">E-mail：</label>
                                    <div class="col-sm-8">
                                        <input id="cemail" type="email" class="form-control" name="email" required="" aria-required="true">
                                    </div>
                                </div>*@

                            <div class="form-group">
                                <label class="col-sm-3 control-label">排序：</label>
                                <div class="col-sm-8">
                                    <input id="iOrder" type="number" class="form-control field" required="" aria-required="true">
                                    <span class="help-block m-b-none">排序越小越靠前</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label" for="bDisplay">是否上架：</label>
                                <input id="bDisplay" type="checkbox" class="field col-sm-3" name="bDisplay" style="height:20px">

                            </div>

                            @*<div class="form-group">
                                    <label class="col-sm-3 control-label">排序：</label>
                                    <div class="col-sm-8">
                                        <input id="OrderIndex" type="number" class="form-control field" required="" aria-required="true">
                                    </div>
                                </div>*@
                            <input id="Id" style="display:none" class="form-control field">
                            @*<div class="form-group">
                                    <label class="col-sm-3 control-label">说明：</label>
                                    <div class="col-sm-8">
                                        <textarea id="ccomment" name="comment" class="form-control" required="" aria-required="true"></textarea>
                                    </div>
                                </div>*@
                            @*<div class="form-group">
                                    <div class="col-sm-4 col-sm-offset-3">
                                        <button class="btn btn-primary" type="submit">提交</button>
                                    </div>
                                </div>*@
                        </form>
                    </div>

                </div>
                <div class="modal-footer">

                    <div class="pull-left">
                        <div id="selDiv" class="checkbox i-checks checkbox-inline pull-left">

                            @*<label id="lblcopy"><input type="checkbox" class="i-checks" checked id="copynew">复制新增</label>*@

                        </div>

                    </div>

                    <button id="dia_ok" type="button" class="btn btn-primary" onclick="doSave()">提交</button>
                    <button id="dia_close2" type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>

}

@section scripts {
    <script type="text/javascript">
        sortName = "dAddTime";
    sortOrder = "desc";
    $tableurl = "/Order/OrderListTable";
    $pageSize = 25;
    $escape = false;
    $pagination = true
    $singleSelect=true
    columns = [
             {
                 checkbox: true,
                 align: 'center',
                 valign: 'middle'
             }, {
                 title: '订单号',
                 field: 'OrderNo',
                 align: 'center',
                 valign: 'middle',
                 //editable: true,
             }, {
                 title: '描述',
                 field: 'Title',
                 align: 'center',
                 valign: 'middle',
                 //sortable:true
                 //editable: true,
             }, {
                 title: '商品数量',
                 field: 'TotalNumber',
                 align: 'center',
                 valign: 'middle',
                 //sortable:true
                 //editable: true,
             }, {
                 title: '总金额',
                 field: 'TotalAmount',
                 align: 'right',
                 valign: 'middle',
                 //sortable:true
                 //editable: true,
             }, {
                 title: '状态',
                 field: 'OrderStatusText',
                 align: 'center',
                 valign: 'middle',
                 sortable: true,
                 cellStyle: function (value, row, index) {
                     var bgcolor = "";
                     var color = "";
                     if (row.OrderStatus == 10)
                         bgcolor = 'yellow'
                     else if (row.OrderStatus == 20) {
                         bgcolor = 'red'
                         color = "white"
                     }
                     else if (row.OrderStatus == 30) {
                         color = "white"
                         bgcolor = 'green'
                     }
                     else if (row.OrderStatus == 40)
                         color = 'black'
                     return {
                         css: {
                             "background-color": bgcolor,
                             "color": color,
                         }
                     }
                 },
                 //editable: true,
             }, {
                 title: '添加时间',
                 field: 'dAddTime',
                 align: 'center',
                 valign: 'middle',
                 sortable: true
                 //editable: true,
             }, {
                 title: '客户备注',
                 field: 'Comment',
                 align: 'center',
                 valign: 'middle',
                 sortable: true,
                 cellStyle: function (value, row, index) {
                     return {
                         css: {
                             "color": 'red',
                         }
                     }
                 },
                 //editable: true,
             }, {
            title: '收货人',
            field: 'cPerson',
            align: 'center',
            valign: 'middle',
            sortable: true
            //editable: true,
        }, {
            title: '联系电话',
            field: 'cTel',
            align: 'center',
            valign: 'middle',
            sortable: true
            //editable: true,
        }, {
            title: '地址',
            field: 'cAddress',
            align: 'center',
            valign: 'middle',
            sortable: true
            //editable: true,
        }
    ]

    function queryParams(params) {
        return {
            pageSize: params.limit,
            pageIndex: parseInt(params.offset / params.limit) + 1,//加1，与jqgrid保持一致
            sort: params.sort,
            order: params.order,
            filter: params.search,
            orderstatus: $("#orderstatus").val()
        };
    }


    $(function () {

        $loadTable(initTable);

    });

    function $onLoadSuccess(data) {
    }
    var options = document.getElementById("Title").options
    function doAdd(type, dblrow) {
        var row = getIdSelections();
        if (dblrow)
            row = [dblrow];
        if (row.length == 0) {
            if (type == 2) {
                showTip('请选择数据！', "error");
                return;
            }
        }


        $("#Title").val("")
        $("#iOrder").val("")
        $("#Id").val("")
        $("#bDisplay")[0].checked = true;

        if (type == 2) {
            //记录这里复制
            $("#Title").val(row[0].Title)
            $("#iOrder").val(row[0].iOrder)
            $("#Id").val(row[0].Id)
            $("#bDisplay")[0].checked = row[0].bDisplay == "是"

        } else {
            var orderindex = AjaxPost("../../Product/GetGoodsOrderIndex", {}, false)
            $("#iOrder").val(orderindex)
        }

        $('#EditModal').modal({ backdrop: 'static', keyboard: false });

        $("#dia_icon").addClass("fa-question-circle").removeClass("fa-exclamation");

        $("#dia_close").show();
        $("#dia_close2").show().text("关闭");
        $("#dia_ok").show().text("确定");
    }
    function $rowDoubleClick(row) {
        //doAdd(2, row)
        //doEditContent(row)
        parent.openTab('../Order/OrderDetail/Detail/' + row.Id, '订单明细')
    }
    function doSave() {
        var data = GetFormData();
        if (String.IsNullOrEmpty(data.Title)) {
            showTip('商品名称不能为空！', "error");
            return
        }

        var res = AjaxPost("../../Product/Edit", data, false);
        if (!String.IsNullOrEmpty(res)) {
            showTip(res, "error");
            return
        } else {
            showTip("保存成功", "success");
            refreshTable();
        }
        $('#EditModal').modal('hide')

    }
    function btn_delete() {
        var row = getIdSelections();
        if (row.length == 0) {
            showTip('请选择需要删除的数据！', "error");
            return;
        }
        $('#myModal').modal({ backdrop: 'static', keyboard: false });

        $("#dia_icon").addClass("fa-question-circle").removeClass("fa-exclamation");
        $("#dia_title").text("商品删除");
        $("#dia_info").text("商品被删除后不能恢复。\n 请谨慎操作！");
        $("#dia_close").show();
        $("#dia_close2").show().text("关闭");
        $("#dia_ok").show().text("确定");
    }
    function doConfirm() {
        var row = getIdSelections();
        if (row.length == 0) {
            showTip('请选择需要删除的数据！', "error");
            return;
        }
        var Id = row[0].Id;
        var count = AjaxGet('../../Product/DeleteGoods', { id: Id }, false);
        if (count == 1) {
            showTip("删除成功", "success");
            refreshTable();
            $('#myModal').modal('hide')
        }
    }
    function doUpOrDown(type) {
        var rows = getIdSelections();
        if (rows.length == 0) {
            showTip('请选择数据！', "error");
            return;
        }
        var data = {};
        data.display = type;
        data.Id = rows[0].Id;
        var res = AjaxPost("../../Product/UpDownGoods", data, false);
        if (res == 1) {
            showTip("操作成功", "success");
            refreshTable();
        }
    }
    function $rowClick(row) {

    }
    function $onRowEditableSave(field, row, oldValue, $el) {

    }
    function doEditContent(row) {
        var rows = getIdSelections();
        if (row)
            rows[0] = row
        if (rows.length == 0) {
            showTip('请选择要编辑的商品！', "error");
            return;
        }
        window.location.href = "../Product/Content?gid=" + rows[0].Id;
    }
    function doSyncPayResult() {
        var rows = getIdSelections();
        if (!rows || rows.length == 0) {
            showTip('请选择要同步的订单！', "error");
            return;
        }
        if (rows[0].OrderStatus != 10) {
            showTip('请选择订单状态为【待付款】的订单！', "error");
            return;
        }
        var res = AjaxPost("../../Order/SyncPayResult", { OrderId: rows[0].Id }, false);
        if (res) {
            showTip("操作成功，该订单已支付", "success");
            refreshTable();
        } else {
            showTip("操作成功，该订单未支付", "success");
        }
    }
    </script>
}